Skip to main content
Version: 1.x.x

Query Params


Request query parameters

The use of query params is based on built-in parser. We can freely change its options and format to match our needs.


Setting query params

You can set query params by using the setQueryParams method on command. It's type can be configured on command creation.

type QueryParamsType = {
search: string;
sort: string;
};

const getUsers = builder.createCommand<Response, void, void, QueryParamsType>()({ endpoint: "/users" });

// Setting the query params

const command = getUsers.setQueryParams({ search: "John", sort: "age" });
console.log(command.endpoint); // Output: "/users?search=John&sort=age"
const getUsers = builder.createCommand<Response, void, void, string>()({ endpoint: "/users" });

const command = getUsers.setQueryParams("search=John&sort=age");
console.log(command.endpoint); // Output: "/users?search=John&sort=age"

Custom query params format

We can setup custom config with instructions how to stringify the values. It can be setup on the builder with setQueryParamsConfig method.

Available options:

{
arrayFormat: bracket | index | comma | separator | bracket-separator | none;
arraySeparator: string;
encode: boolean;
skipEmptyString: boolean;
skipNull: boolean;
strict: boolean;
}